package com.dyh.quickdemo.GoodsRules;

import java.util.function.Function;
import java.util.function.Predicate;

/*
@Author=Joey Wheeler
@Date=2021/3/6 11:09
*/
public class Rules {



//    public static <A,B> Rule must(Function<A,B> mapper, Predicate<B> predicate, String tip){
//        return new Rule$1<>(mapper,predicate,tip);
//    }

    public static Rule$1 limit(Rule$1Builder builder){
        return builder.build();
    }

    public  static  <T>Checker$1<T> not(Checker$1<T> predicate){
        return t->!predicate.test(t);
    }


    public static <T> CheckResult check(T a,Rule<T>... rules){
        CheckResult checkResult = null;
        for (Rule<T> rule : rules) {
            if (!(checkResult = rule.check(a)).isPass())
                return checkResult;
        }
        return checkResult;
    }

//    public static <T> CheckResult check(T a,Rule<T>... rules){
//        CheckResult checkResult = null;
//        for (Rule<T> rule : rules) {
//            if (!(checkResult = rule.check(a)).isPass())
//                return checkResult;
//        }
//        return checkResult;
//    }

}
